<?php

namespace Home\Controller;

/**
 * Description of CustomerPageController.class控制器实例
 *
 * @author zhangzhen
 * @date 2017-02-13
 */
class CustomerPageController extends ParentController {

    protected function _initialize() {
    	parent::_initialize();
        $this->validateUtil = new \Org\Util\Validate();
    }
    public function vip() {
        $hotelId = $this->hotelId;
        $userId = getUserId();
        //检查是否超级管理员
        $adminAuthorityLogic = A('Common/AdminAuthority','Logic');
        $hasRight = $adminAuthorityLogic->checkIsAdmin($userId,$hotelId);

        if (empty($hasRight)) {
            $this->assign('hasRight',0);
            $AdminHotelModel = D('AdminHotel');
            $adminHotelInfo = $AdminHotelModel->getHotelCreator($hotelId);
            $creator = $adminHotelInfo['adminlogin_id'];
        }else{
            $this->assign('hasRight',1);
            $creator = $userId;
        }
        //检查是否初始化
        $vipInitModel = D('VipInit');
        $vipInitInfo = $vipInitModel->getInfoByAdmin($creator); 
        if(empty($vipInitInfo)){
            $this->assign('init',0);
        }else{
            $vipInfoModel = D('VipInfo');
            $vipInfos = $vipInfoModel->getInfoByHotel($hotelId); 

            $this->assign('initInfo', $vipInitInfo);
            $this->assign('vipInfos', $vipInfos);
            $this->assign('init',1);
        }

        $hotelLogic = A('Common/Hotel', 'Logic');
        $hotelPayData = $hotelLogic->getHotelPay($hotelId, false);
        $this->assign('hotelpay', $hotelPayData);

        $this->display();
    }
    public function vipSetting() {
        $hotelId = $this->hotelId;
        $userId = getUserId();
        //检查是否超级管理员
        $adminAuthorityLogic = A('Common/AdminAuthority','Logic');
        $hasRight = $adminAuthorityLogic->checkIsAdmin($userId,$hotelId);

        if (empty($hasRight)) {
            $this->assign('hasRight',0);
            $AdminHotelModel = D('AdminHotel');
            $adminHotelInfo = $AdminHotelModel->getHotelCreator($hotelId);
            $creator = $adminHotelInfo['adminlogin_id'];
        }else{
            $this->assign('hasRight',1);
            $creator = $userId;
        }
        //检查是否初始化
        $vipInitModel = D('VipInit');
        $vipInitInfo = $vipInitModel->getInfoByAdmin($creator); 
        if(empty($vipInitInfo)){
            $this->assign('init',0);
        }else{
            $vipInfoModel = D('VipInfo');
            $vipInfos = $vipInfoModel->getInfoByHotel($hotelId); 

            $this->assign('initInfo', $vipInitInfo);
            $this->assign('vipInfos', $vipInfos);
            $this->assign('init',1);
        }
        $this->display();
    }
    public function index() {
        $param = I('param.');

        $startDate = $param['start'];
        $startDate = empty($startDate) ? date('Y-m-01') : $startDate;
        $endDate = $param['end'];
        $endDate = empty($endDate) ? date('Y-m-d') : $endDate;

        $startTime = strtotime($startDate);
        $endTime = strtotime($endDate);
        // 最多只能查询30天
        if (getTimeDiff($startTime, $endTime, 'day') >= 30) {
            $endDate = date('Y-m-d', strtotime('+30 days', $startTime));
        }

        $this->assign('startDate', $startDate);
        $this->assign('endDate', $endDate);

        $this->display();
    }
}
